{extend name="public/base"/}
{block name="style"}
{/block}
{block name="content"}
<div class="data-list">
    <div class="layui-row">
        <div class="layui-inline">
            <input type="text" class="layui-input" autocomplete="off" autofocus="autofocus" id="sku" placeholder="sku">
        </div>
        <div class="layui-inline">
            <button type="button" class="layui-btn layui-btn-sm layui-btn-normal btn-search"><i class="layui-icon layui-icon-search"></i></button>
        </div>
    </div>
    <div class="data">
    </div>
</div>
{/block}
{block name="script"}
<link rel="stylesheet" href="__PUBLIC__/css/print.min.css">
<script type="text/javascript" src="__PUBLIC__/js/print.min.js"></script>
<script type="text/javascript">
    layui.use(['layer', 'jquery', 'longli'], function()
    {
        var layer = layui.layer
            , $ = layui.jquery;
        $("#sku").keydown(function(event)
        {
            if(event.keyCode != 13) return;
            $(".btn-search").click();
            $(this).val('');
        });

        $(".btn-search").click(function()
        {
            var $input = $("#sku")
                , sku = $input.val().trim();
            if(!sku) return false;
            $.post("{:url('index')}", {sku}).done(function(response)
            {
                if(response.data.type) layui.longli.playMP3(response.data.type);
                var icon = 5;
                if(response.code == 1)
                {
                    icon = 6;
                    if(response.data.html) $(".data").html(response.data.html);
                    printJS({printable: response.data.file, type: 'pdf', base64: true, showModal:true})
                }
                layer.msg(response.msg, {icon: icon, time: 1500});
            });
        });
    });
</script>
{/block}